@import (reference) 'config';
@import (reference) 'icons';
@import (reference) '../../../app/less/app';

@candy-animation: candyDotsAnimation 1.6s infinite ease-in-out;
@candy-size: 10px;

.fake-button,
w-button {
  display: inline-block;
  border-radius: @border-radius;
  white-space: nowrap;
  cursor: pointer;

  &.long {
    width: 100%;
  }

  &.half {
    width: 50%;
  }

  &.long > *, &.half > * {
    width: 100%;
  }

  .fake-button-content {
    display: block;
  }

  .fake-button-content,
  & > * {
    transition: all 0.3s;
    border-radius: @border-radius;
    padding: 0;
    border: 0 none;
    width: 100%;
    background-color: @color-white;
    box-shadow: 0 0 0 1px @color-basic-200 inset;
    color: @color-basic-500;

    &.tiny {
      font-size: @font-size-control-tiny;
      padding: @padding-control-tiny;
    }

    &.small {
      font-size: @font-size-control-small;
      padding: @padding-control-button-small;
    }

    &.big {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      text-align: center;
      height: @height-control-big;
      font-size: @font-size-control-big;
      font-family: @font-roboto-medium;
    }

    &:hover, &.hover,
    &:active, &.active {
      box-shadow: 0 0 0 1px @color-basic-500 inset;
      color: @color-basic-700;
    }

    &:disabled, &.disabled {
      color: @color-basic-200;
    }

    &.tiny {
      font-size: 12px;
      padding: 0 10px;
      height: 30px;
      line-height: 30px;
    }

    &.small {
      font-size: 13px;
      padding: 0 20px;
      height: 36px;
      line-height: 36px;
    }

    &.medium {
      font-family: @font-roboto-medium;
      font-size: 15px;
      padding: 0 20px;
      height: 42px;
      line-height: 42px;
    }

    &.micro {
      font-size: @font-size-control-micro;
      padding: @padding-control-button-micro;
    }

    &.big {
      font-family: @font-roboto-medium;
      font-size: 17px;
      padding: 0 24px;
      height: 54px;
      line-height: 54px;
      @media screen and (max-width: 768px) {
        height: @height-control-big-responsive;
        line-height: @height-control-big-responsive;
        font-size: @font-size-control-big-responsive;
      }
    }

    &.micro {
      background-color: @color-white;
      border: 1px solid @color-basic-100;
      color: @color-basic-700;

      &:hover, &.hover {
        border-color: @color-submit-300;
        color: @color-basic-700;
      }

      &:disabled, &.disabled {
        border: 1px solid @color-accent-50;
        color: @color-basic-500;
      }
    }

    &.no-padding {
      padding: 0;
    }

    &.transparent {
      background: transparent;
      color: @color-white;
      box-shadow: none;
    }

    &.success {
      box-shadow: none;
      background-color: @color-success-300;
      color: @color-white;

      &:hover, &.hover {
        background-color: @color-success-400;
      }

      &:active, &.active {
        background-color: @color-success-500;
      }

      &:disabled, &.disabled {
        background-color: @color-success-100;
      }
    }

    &.submit {
      box-shadow: none;
      background-color: @color-submit-400;
      color: @white-only;

      &:hover, &.hover {
        background-color: @color-submit-500;
      }

      &:active, &.active {
        background-color: @color-submit-600;
      }

      &:disabled, &.disabled {
        background-color: @color-submit-400;
        opacity: 0.3;
      }

      &-light {
        background: @color-submit-50;
        color: @color-submit-400;
        box-shadow: none;

        &:hover {
          background: @color-submit-100;
          color: @color-submit-400;
        }
      }
    }

    &.warning {
      box-shadow: none;
      background-color: @color-error-400;
      color: @white-only;

      &:hover, &.hover,
      &:active, &.active {
        background-color: @color-error-600;
        border-color: transparent;
      }

      &:disabled, &.disabled {
        background-color: @color-error-200;
        box-shadow: inset -1px 1px 0 0 rgba(255, 255, 255, 0);
      }
    }

    &.interface {
      background-color: @color-white;
      border: none;
      color: @color-basic-700;
      font-family: @font-roboto-medium;
      font-size: 15px;
      height: 42px;
      line-height: 42px;
      padding: 0 20px;
      text-transform: capitalize;
      box-shadow: @shadow-buttons-default;
      transition: all 0.3s;
      white-space: nowrap;

      &:hover, &.hover {
        box-shadow: @shadow-buttons-hover;
        color: @color-basic-700;
        svg {
          fill: @color-basic-700;
        }
      }

      svg {
        transition: .3s;
        vertical-align: middle;
        fill: @color-basic-500;
        margin-right: 7px;
        margin-top: -3px;
        margin-left: -4px;

        @media screen and (max-width: 560px) {
          margin-right: 0;
          margin-left: 0;
        }
      }

      &:active, &.active {
        box-shadow: @shadow-buttons-hover;
        color: @color-basic-500;
      }

      &:disabled, &.disabled {
        opacity: 0.5;
        cursor: default;
        border: none;
      }

      &.bordered {
        box-shadow: none;
        border: 1px solid @color-basic-100;
      }
    }
  }

  &:active, &.active {
    &:not(.transparent) {
      .micro {
        &,
        &:hover {
          border-color: @color-submit-300;
          color: @color-submit-300;
        }
      }
    }
  }
}

.buttons-wrapper {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;

  w-button,
  .fake-button {
    display: block;
    flex-basis: 48%;
    max-width: 48%;
  }

  &-nowidth {
    width: auto;
    justify-content: flex-start;

    w-button,
    .fake-button {
      flex-basis: auto;
      max-width: none;
    }
  }
}

//Candy effect
w-button {
  w-loader {
    display: none;
  }

  &.pending {

    .button__content {
      display: none;
    }

    w-loader {
      display: block;
      margin: 0 auto;

      .loader-dots() {
        position: absolute;
        width: @candy-size;
        height: @candy-size;
        border-radius: 50%;
        top: -12px;
        left: calc(50% ~'- 5px');
        display: inline-block;
        animation-fill-mode: both;
        animation: @candy-animation;
      }

      .preloader {
        .loader-dots();
        top: -12px;
        animation-delay: .16s;

        &::before,
        &::after {
          .loader-dots();
          top: 0;
          content: '';
        }

        &::before {
          transform: translateX(-15px);
          animation-delay: 0s;
        }

        &::after {
          transform: translateX(15px);
          animation-delay: .32s;
        }
      }

    }
  }

  @keyframes candyDotsAnimation {
    0%,
    80%,
    100% {
      box-shadow: 0 13px 0 0 @color-white,
      0 15px 0 0 transparent;
    }
    40% {
      box-shadow: 0 13px 0 -13px @color-white;
    }
  }
}

/* Mac button text centering fix */
w-button > button {
  w-i18n,
  div.button__content,
  div.full-width,
  div.full-width * {
    width: 100%;
    display: block;
  }
}

@media screen and (max-width: 768px) {
  w-button {
    & > * {
      //padding-top: 8px;
      //padding-bottom: 8px;
      white-space: nowrap;
    }
  }
}


.btn-wrap.btn-group {
  box-sizing: border-box;
  padding: 0;
  display: flex;
  flex-direction: row;
  justify-content: center;

  & > *:first-child .btn, & > .btn:first-child {
    border-left: 1px solid @color-disabled-100;
    border-bottom-left-radius: 5px;
    border-top-left-radius: 5px;
  }

  & > *:last-child .btn, & > .btn:last-child {
    border-bottom-right-radius: 5px;
    border-top-right-radius: 5px;
  }

  .btn {
    display: block;
    box-sizing: border-box;
    cursor: pointer;
    padding: 4px 10px;
    border-bottom: 1px solid @color-disabled-100;
    border-top: 1px solid @color-disabled-100;
    border-right: 1px solid @color-disabled-100;

    &:active {
      .btn-active();
    }
  }
}
